package com.example.qt.ptplatform.mapper;

import com.example.qt.ptplatform.entity.LoginLog;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface LoginLogMapper {

    // 插入一条登录记录
    @Insert("INSERT INTO login_logs (user_id, ip_address, login_time, location)" +
            "VALUES (#{userId}, #{ipAddress}, #{loginTime}, #{location})")
    void insertLoginLog(LoginLog loginLog);

    // 查询用户在一定时间范围内的登录记录
    @Select("SELECT * FROM login_logs WHERE user_id = #{userId} AND login_time > #{startTime}")
    List<LoginLog> getRecentLoginLogs(@Param("userId") Integer userId, @Param("startTime") LocalDateTime startTime);
}
